﻿#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace MediaWiki.Office.Packaging
{
  public class PackageRelationship
  {
    public static readonly XNamespace Namespace = XNamespace.Get("http://schemas.openxmlformats.org/package/2006/relationships");

    public static readonly Uri ContainerRelationshipPartName = new Uri("/_rels/.rels", UriKind.Relative);

    private string _id;
    private IPackage _package;
    private string _relationshipType;
    private IPackagePart _source;
    private TargetMode _targetMode;
    private Uri _targetUri;

    public PackageRelationship(IPackage package, IPackagePart sourcePart, Uri targetUri, TargetMode targetMode, string relationshipType, string id)
    {
      if (package == null)
        throw new ArgumentNullException("package");

      if (targetUri == null)
        throw new ArgumentNullException("targetUri");

      if (relationshipType == null)
        throw new ArgumentNullException("relationshipType");

      if (id == null)
        throw new ArgumentNullException("id");

      _package = package;
      _source = sourcePart;
      _targetUri = targetUri;
      _relationshipType = relationshipType;
      _targetMode = targetMode;
      _id = id;
    }

    /// <summary>
    /// Gets the relationship Id.
    /// </summary>
    /// <value>The id.</value>
    public string Id
    {
      get { return _id; }
    }

    /// <summary>
    /// Gets the relationship package.
    /// </summary>
    /// <value>The package.</value>
    public IPackage Package
    {
      get { return _package; }
    }

    /// <summary>
    /// Gets the relationship type.
    /// </summary>
    /// <value>The type of the relationship.</value>
    public string RelationshipType
    {
      get { return _relationshipType; }
    }

    /// <summary>
    /// Gets the URI of the source part.
    /// </summary>
    /// <value>The source URI.</value>
    public Uri SourceUri
    {
      get
      {
        if (_source == null)
          return PackageUriHelper.PackageRootUri;

        return _source.Uri;
      }
    }

    /// <summary>
    /// Gets the relationship target mode.
    /// </summary>
    /// <value>The target mode.</value>
    public TargetMode TargetMode
    {
      get { return _targetMode; }
    }

    /// <summary>
    /// Gets the relationship target URI.
    /// </summary>
    /// <value>The target URI.</value>
    public Uri TargetUri
    {
      get { return _targetUri; }
    }
  }
}